package com.dragon.pond.customer.service;

import com.dragon.pond.customer.domain.Customer;
import com.dragon.pond.customer.repository.CustomerRepository;
import com.dragon.pond.order.domain.Order;
import com.dragon.pond.order.repository.OrderRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

/**
 * Created by JACK on 2017/4/20.
 */
@Service
@Transactional
public class CustomerService {
    @Autowired
    private CustomerRepository customerRepository;

    @Autowired
    private OrderRepository orderRepository;

    public List<Customer> loadList(){
        return customerRepository.findAll();
    }

    public void createNewCustomerAndInitOrder() {
        Customer customer = new Customer();
        customer.setName("JACK");
        customer.setAge(32);
        customerRepository.save(customer);

        Order order = new Order();
        order.setCode(10020202);
        order.setQuantity(1000);
        orderRepository.save(order);

        throw new RuntimeException("意外引发异常");
    }
}
